import "package:ct_pa_majordomo/utils/request.dart";
import "package:dio/dio.dart";

class ElectricityMeterApi {
  /* 获取电表列表 */
  Future<Map> getElectricityMeterList(queryParameters) async {
    Response response = await request.get(
      "apartment/ammeter/list",
      queryParameters: queryParameters,
    );
    return response.data ?? {};
  }

  /* 获取电表详情 */
  Future<Map> getElectricityMeterInfo(electricityMeterId) async {
    Response response = await request.get(
      "apartment/ammeter/$electricityMeterId",
    );
    return response.data ?? {};
  }

  /* 电表开关闸 queryParameters[type] 10: 拉闸，11: 合闸； */
  Future<Map> onOffChange(queryParameters) async {
    Response response = await request.post(
      "apartment/ammeter/on-off-change",
      queryParameters: queryParameters,
    );
    return response.data ?? {};
  }

  /* 同步指定电表信息 */
  Future<Map> syncOnce(queryParameters) async {
    Response response = await request.post(
      "apartment/ammeter/sync-once",
      queryParameters: queryParameters,
    );
    return response.data ?? {};
  }

  /* 新增电表信息编辑 */
  Future<Map> saveElectricityMeter(queryParameters) async {
    Response response = await request.post(
      "apartment/ammeter",
      data: queryParameters,
    );
    return response.data ?? {};
  }

  /* 电表信息编辑 */
  Future<Map> editElectricityMeter(queryParameters) async {
    Response response = await request.put(
      "apartment/ammeter",
      data: queryParameters,
    );
    return response.data ?? {};
  }

  /* 删除电表 */
  Future<Map> removeElectricityMeter(electricityMeterIds) async {
    Response response = await request.delete(
      "apartment/ammeter/$electricityMeterIds",
    );
    return response.data ?? {};
  }

  /* 未绑定电表 */
  Future<Map> unbindList() async {
    Response response = await request.get(
      "apartment/ammeter/unbind-list",
    );
    return response.data ?? {};
  }

  /* 电表绑定房间 */
  Future<Map> bindRoom(data) async {
    Response response = await request.put(
      "apartment/ammeter/bind-room",
      queryParameters: data,
    );
    return response.data ?? {};
  }

  /* 电表解绑房间 */
  Future<Map> unbindRoom(int id) async {
    Response response = await request.post(
      "apartment/ammeter/unbind/$id",
    );
    return response.data ?? {};
  }

  /* 电表解绑房间 */
  Future<Map> useRecord(queryParameters) async {
    Response response = await request.get(
      "apartment/record/list/${queryParameters["electricityMeterId"]}",
      queryParameters: queryParameters
    );
    return response.data ?? {};
  }

  /* 电表开户 */
  Future<Map> openElectricityMeter(data) async {
    Response response = await request.post(
      "apartment/ammeter/open/${data["electricityMeterId"]}",
      data: data
    );
    return response.data ?? {};
  }

  /* 电表清零 */
  Future<Map> resetElectricityMeter(int electricityMeterId) async {
    Response response = await request.post(
      "apartment/ammeter/reset/$electricityMeterId"
    );
    return response.data ?? {};
  }

  /* 电表充值 */
  Future<Map> rechargeElectricityMeter(data) async {
    Response response = await request.post(
      "apartment/ammeter/recharge/${data["electricityMeterId"]}",
      data: data
    );
    return response.data ?? {};
  }
}

ElectricityMeterApi electricityMeterApi = ElectricityMeterApi();